use bytes::{Buf, BufMut};

use crate::error::buf_err::{FromBufError, ToBufError};

///写入指定的缓冲区
pub trait ToBuf {
	type Target: BufMut;

	fn write_to(&self, target: &mut Self::Target) -> Result<(), ToBufError>;
}

///从buf获取相应的数据
pub trait FromBuf {
	type From: Buf;

	///将所有的数据全部进行转换.
	/// 此时传入的from将不保证正确的指针
	fn from_buf_all(from: Self::From) -> Result<Self, FromBufError>
	where
		Self: Sized;

	///根据自身规则,吃掉from中的一块,并转换成自身
	fn from_buf(from: &mut Self::From) -> Result<Self, FromBufError>
	where
		Self: Sized;
}
